package eval.hostEvaluate;

import java.util.List;
import java.util.Map;
import eval.host.Host;
import eval.vm.VirtualMachine;

public class SimpleEvaluation implements IHostEvaluate{
	
	
	
	@Override
	public int evaluationForHost(Host host,VirtualMachine vmToBeDeployed,
			List<VirtualMachine> vmsAlreadyInHost,Map<VirtualMachine, Integer> cpuDemandOfVMs,
			Map<VirtualMachine, Integer> memDemandOfVMs) {
		//this.satisfiedCpuDemand = new HashMap<VirtualMachine, Integer>();
		//sum of minimum CPU of vm in host 
		int cpuMinCount = 0;
		int memCount = 0;
		//sum of demand CPU of vm in host at current tick
		int cpuDemandCount = 0;
		//calc the demand of already in host (cost / power already calc at demand window)
		for (VirtualMachine virtualMachine : vmsAlreadyInHost) {
			cpuMinCount 	+= virtualMachine.getVMConfiguration().getMinCpu();
			cpuDemandCount  += cpuDemandOfVMs.get(virtualMachine).intValue();
			memCount += memDemandOfVMs.get(virtualMachine).intValue();
		}
		// add vm to be deployed to count
		cpuMinCount 	+= vmToBeDeployed.getVMConfiguration().getMinCpu();
		cpuDemandCount  += cpuDemandOfVMs.get(vmToBeDeployed).intValue();
		memCount += memDemandOfVMs.get(vmToBeDeployed).intValue();
		if(cpuMinCount > host.getHostCapacity().getCpuCapacity()) 
			return Integer.MIN_VALUE;
		if(memCount > host.getHostCapacity().getMemCapacity())
			return Integer.MIN_VALUE;
		return host.getHostCapacity().getCpuCapacity()- cpuDemandCount;
		/*
		int score = host.getHostCapacity().getCpuCapacity()- cpuDemandCount; 
		if(score<=0)
			return Integer.MIN_VALUE;
		return score;*/
		
	}
}
